package com.wh.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wh.mapper.UserMapper;
import com.wh.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.UUID;

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public String findUserByUP(User user) {
        String md5Pass = DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
        user.setPassword(md5Pass);
        QueryWrapper queryWrapper = new QueryWrapper(user);
        User userDB = userMapper.selectOne(queryWrapper);

        String token = UUID.randomUUID().toString().replace("-", "")+user.getUsername();
        return userDB==null?null:token;
    }
}
